
import allure
import os,time
from datetime import datetime
def  SaveImage(driver,errorImage):
    '''用例失败截图功能'''
    Rawpath =  os.path.join(os.path.dirname(os.path.dirname(__file__)),'Image')
    NewPicture  =  Rawpath + '\\' + time.strftime('%Y_%m_%d_%H_%M_%S') + '_' + errorImage
    allure.attach(Rawpath, errorImage, allure.attachment_type.PNG)
    return driver.get_screenshot_as_file(NewPicture)


def save_screenshot(driver, img_doc):
    '''
    页面截屏保存截图,体现在allure
    :param img_doc: 截图说明
    :return:
    '''
    OUTPUTS_DIR=os.path.join(os.path.dirname(os.path.dirname(__file__)),'Image')
    file_name = OUTPUTS_DIR + "\\{}_{}.png".format(datetime.strftime(datetime.now(), "%Y%m%d_%H_%M_%S"), img_doc)
    driver.save_screenshot(file_name)
    with open(file_name, mode='rb') as f:
        file = f.read()
    allure.attach(file, img_doc, allure.attachment_type.PNG)
    #case_logger.info("页面截图文件保存在：{}".format(file_name))